package com.atguigu.userprofile.mapper;

import com.atguigu.userprofile.bean.UserGroup;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import javax.ws.rs.DELETE;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zhangchen
 * @since 2021-05-04
 */


@Mapper
@DS("mysql")
public interface UserGroupMapper extends BaseMapper<UserGroup> {

        //查询分群包的人数
        @DS("ck")
        @Select(" select bitmapCardinality( ${sql} )  ")
        Long queryUserGroupNum(@Param("sql") String bitmapAndSql);

        @Insert("insert into user_group select #{id}, ${bitmapSql}")
        @DS("ck")
        void saveUserGroupToCk(@Param("id") String id,@Param("bitmapSql") String bitmapAndSql);

        // id=1 ,us = [1,2,3,4,5]
        // orm映射规则中，数据库查询的一行，只能封装为一个Bean
        // 查询的结果必须是多行，将查询的结果封装为一个 List<Bean>
        @Select("select arrayJoin(bitmapToArray(us)) from user_group where user_group_id = #{id}")
        @DS("ck")
       List<String> queryUserGroupFromCkById(String id);


        //删除旧的信息
        @DS("ck")
        @Update(" alter table user_group delete where user_group_id =#{id}")
        void deleteUserGroup(String id);


        @DS("ck")
        @Select(" select  arrayJoin(bitmapToArray( ${sql} ))  ")
        List<String>  queryUserGroupFromCkById2(@Param("sql") String bitmapAndSql);



}
